package com.sdy.healthcode.web.interceptor;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Component
@Slf4j
public class BizInterceptor extends HandlerInterceptorAdapter {
    @Value("${res.app.code}")
    private String appCode;
    
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        return super.preHandle(request, response, handler);
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        request.setCharacterEncoding("UTF-8");
        if (modelAndView != null && (response.getContentType() == null || !(response.getContentType().contains("json") || response.getContentType().contains("JSON")))) {
            String uri = request.getRequestURI().replace(request.getContextPath(), "");
        }
        if(modelAndView != null) {
            String viewName = modelAndView.getViewName();
//            log.info("{} to location :{}", StringUtil.startsWith(viewName, "redirect:")?"redirect":"forward", viewName);
        }
    }
}
